<template>
  <div class="content">
    <!--    销售订单号列表弹窗-->
    <el-dialog
      v-dialogDrag
      :title="$t('market.order')"
      model
      :visible.sync="isstorklDialog"
      :close-on-click-modal="false"
      width="60%"
      :before-close="handleClose"
    >
      <div class="materiel-form">
        <search
          :options="selectData"
          :msg="tacitly"
          @seek="collect"
          @hand="storkSearch"
        />
        <el-button
          type="primary"
          class="btn"
          size="mini"
          @click="storkSearch"
        >
          {{ $t('btn.search') }}
        </el-button>
        <el-button class="btn1" size="mini" type="primary" @click="affirm">{{ $t('market.affirm') }}<!--直接运算--></el-button>
        <el-checkbox
          v-model="fmrp"
          style="margin-left: 10px;"
          class="btn1"
          @change="handleGetUntreated"
        >{{ $t('market.notAffirm') }}<!--未计算的需求单据--></el-checkbox>
      </div>
      <jc-table
        :table-data="storklDialogData"
        :table-header="storkDialogHeader"
        table-height="53vh"
        @selectionChange="storklSelectRow"
        @clickRow="storklSelect"
      >
        <el-table-column type="selection" width="30px" align="center" />
      </jc-table>
      <jc-pagination
        v-show="stork.total > 0"
        :total="stork.total"
        :page.sync="stork.pageNum"
        :limit.sync="stork.pageSize"
        @pagination="handleGetUntreated"
      />
    </el-dialog>
  </div>
</template>
<script>
import { queryTSalOrderList } from '@/api/marketManage/marketOrder'
import { toMxAmina } from '@/components/ToMxamineState'
import search from '@/components/Search'
import searData from '@/components/Search/mixin'
export default {
  components: {
    search
  },
  mixins: [searData],
  props: {
    selece: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      ftype: 29,
      // 客户列表数据分页
      isstorklDialog: true,
      isBOMDialog: false,
      fnumber: '',
      stork: {
        total: 0, // 总条目
        pageNum: 1, // 当前页
        pageSize: 200, // 每页显示多少条数据
        fbillNo: '',
        fpaezText: ''
      },
      fmrp: true,
      storklDialogData: [], // 销售数据
      storkDialogHeader: [
        { label: this.$t('shop.numIndex'), prop: 'fseq', width: '50px' },
        { label: this.$t('market.order'), prop: 'fbillNo', minWidth: '120px' },
        { label: this.$t('market.fmaterial'), prop: 'fnumber', minWidth: '120px' },
        { label: this.$t('shop.fname2'), prop: 'fname', minWidth: '120px' },
        { label: this.$t('market.fmodel'), prop: 'fmodel' },
        { label: this.$t('market.funit'), prop: 'funit', minWidth: '70' },
        { label: this.$t('market.kePushQty'), prop: 'fqty', minwidth: '80' },
        { label: this.$t('market.bomNumber'), prop: 'bomNumber', minWidth: '120px' },
        { label: this.$t('market.paezText1'), prop: 'fpaezText', minWidth: '120px' },
        { label: this.$t('market.consignDate'), prop: 'fdeliveryDate', minWidth: '100px' }
      ],
      prodValue: { XSDDH: '' },
      indexSelf: 0,
      ddlx: '',
      val: []
    }
  },
  created() {
    this.handleGetUntreated()
  },
  methods: {
    // 获取销售订单
    async handleGetUntreated() {
      const DATA = { ...this.stork, search: this.searCollData, fdocumentStatus: 'C', fmrp: this.fmrp ? 0 : 1 }
      const { data: RES, data: total } = await queryTSalOrderList(DATA)
      this.storklDialogData = RES.array.map(item => {
        return (toMxAmina(item))
      })
      this.stork.total = total.total
    },
    // 销售订单弹窗选中
    storklSelectRow(val) {
      this.val = []
      val.map(item => {
        this.val.push(item)
      })
    },
    // 修改BOM版本
    bomOpen(index, ev) {
      this.indexSelf = index
      this.fnumber = ev
      this.isBOMDialog = true
    },
    // bom版本
    bomData(ev) {
      if (ev.FID) {
        const item = this.storklDialogData[this.indexSelf]
        item.bomNumber = ev.FNUMBER
        item.fbomid = ev.FID
      }
      this.isBOMDialog = false
    },
    // 双击选中行
    storklSelect(item) {
      this.prodValue.XSDDH = [{
        ...item }]
      this.$emit('xsddh', this.prodValue)
    },
    // 确认
    affirm() {
      this.prodValue.XSDDH = this.val
      this.$emit('xsddh', this.prodValue)
    },
    storkSearch() {
      this.stork.pageNum = 1
      this.handleGetUntreated()
    },
    // 关闭前回调
    handleClose() {
      this.$emit('xsddh', this.prodValue)
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  @include listBom;
}
.materiel-form {
  display: flex;
  align-items: center;
  flex-direction: row;
  margin-bottom: 15px!important;
  position: relative;

  .materiel-code {
    margin-right: 5px;
    font-weight: bold;
    font-size: 14px;
    min-width: 65px;
    color: #606266;
    line-height: 40px;
  }
  .btn {
    transform: translateY(18%);
    margin-left: 450px !important;
  }
  .btn1 {
    transform: translateY(18%);
  }
  .input-width {
    width: 200px;
    margin-right: 10px;
  }
}
</style>
